/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.panomedic.gui;

import com.panomedic.Constants;
import com.panomedic.core.LUT;
import com.panomedic.utils.Utils;
import com.panomedic.colors.ColorConstants;
import com.panomedic.log4j.Logger;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.prefs.Preferences;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

/**
 *
 * @author Yare
 */
public class LUTDialog extends JDialog {
    
    static Logger logger = new Logger();

    private Preferences prefs;
    JDialog dialog = this;
    private JTabbedPane tabbedPane;
    
    public LUTDialog(Frame owner, String title, LUT lut) {
        super(owner, title);
        prefs = Preferences.userRoot().node(Constants.defNodePath);

        tabbedPane = new JTabbedPane();

        
        JPanel[] lutPanel = new JPanel[Constants.getNumCompProc()];
        int j = 0;
        for (int i = 0; i < ColorConstants.NUM_COMP; i++, j++) {
            if (Utils.getCompProc(prefs.getInt(Constants.COMP_PROC, 0))[i]) {
                lutPanel[j] = new LUTPanel(lut, i);
                tabbedPane.addTab(ColorConstants.getCompName(prefs.getInt(Constants.CS_TYPE, ColorConstants.HSV), i), lutPanel[j]);
            }
            else j--;
         }

        JButton closeButton = new JButton("Close");
        closeButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dialog.setVisible(false);
                dialog.dispose();
            }
        });
        JPanel closePanel = new JPanel();
        closePanel.setLayout(new BoxLayout(closePanel,
                BoxLayout.LINE_AXIS));
        closePanel.add(Box.createHorizontalGlue());
        closePanel.add(closeButton);
//        closePanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 5, 5));

        JPanel contentPane = new JPanel(new BorderLayout());
        contentPane.add(tabbedPane, BorderLayout.CENTER);
        contentPane.add(closePanel, BorderLayout.PAGE_END);
        contentPane.setOpaque(true);
        this.setContentPane(contentPane);

        //Show it.
        this.setSize(new Dimension(450, 430));
        this.setLocationRelativeTo(owner);
        this.setVisible(true);
    }

    public JTabbedPane getTabbedPane() {
        return tabbedPane;
    }
    
    
    public static void main(String[] args){
        final JFrame f = new JFrame("Swing Paint Demo");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
        JButton closeButton = new JButton("Show");
        closeButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                LUTDialog dialog = new LUTDialog(f,new String("testing dialog"), null);
            }
        });
        
        f.add(closeButton);
//        f.add(new LUTPanel(null));
        f.pack();
        f.setVisible(true);
//        LUTDialog dialog = new LUTDialog(f,new String("testing dialog"));

        
    }
}

